/**
 * Created by fengtao on 15-11-13.
 */
/**
 * 输出，调试用
 * @param data
 */
function sysEcho(data) {
    console.log(data);
    alert(data);
}

/**
 * --------------------------------------->>>分页方法>>>------------------------------------
 */
/**
 * 分页展现数据
 * @param url
 * @param param 参数对象eg:{pageSize:xx,pageNo:xx,---}
 * @param btn 自定义操作按钮
 */
function pagingData(url,param,btn) {
    param.pageNo = (param.pageNo==null?1:param.pageNo);
    var pageSize=$("#pageSize option:selected").text();
    param.pageSize=(pageSize==null?10:pageSize);
    $.ajax({
        url: url,
        type: "post",
        dataType: 'json',
        async: false,
        data: param,
        error: function (data) {
            console.log(data);
            layer.msg(data.message,{time:2000});
        },
        success: function (jsons) {
            if(jsons.code == 500){
                layer.msg(jsons.errorMessage);
            }else if (jsons.code == 201){
                layer.msg("数据为空！");
            }else{
                pageTable(jsons.pageData,btn);
            }
        }
    });
}
/**
 * @desc 处理分页统一方法
 * @author huangjc
 * @param pageData pageData.pageList 分页数据,pageData.title 表头数据
 * @param btn 定制按钮
 */
function pageTable(pageData,btn){
    //清空table下数据
    $("#pageTable").html("");
    $("#pageTitle").html("");
    //获取信息
    var pageList = pageData.pageList;
    var pageTitle = pageData.title;
    //主键字段
    var ID_FIELD=pageTitle["ID"];
    //拼接表头
    var tableTitle = '';
    for(var key in pageTitle){
        //如果不是ID属性则拼接，ID在页面不显示
        if(key !=="ID"){
            tableTitle += '<th class="control-width">' +((pageTitle[key] == undefined || pageTitle[key] == null) ? '' : pageTitle[key])+ '</th>';
        }
    }
    if(btn != null && btn != ""){
        tableTitle = '<tr><th class="checkwidth control-width"><input type="checkbox" onclick="selectAll(this);" class="checkAll" title="全选"/></th>' +tableTitle+ '<th class="operation control-width" style="width:150px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;操&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;作&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th></tr>';
    }else{
        tableTitle = '<tr><th class="checkwidth control-width"><input type="checkbox" onclick="selectAll(this);" class="checkAll" title="全选"/></th>' +tableTitle+ '</tr>';
    }

    //拼接具体数据
    //添加到表头中
    $(tableTitle).appendTo("#pageTitle");
    for (var i = 0; i < pageList.length; i++) {
        //表格内容
        var partsList = '';
        //选择框
        var checkId = '';
        for(key in pageTitle){
            //属性值
            var pro_value;
            if(key == "ID"){
                pro_value = pageList[i][ID_FIELD] == null ? '' :pageList[i]["ID"];
                checkId = '<td class="checkNot" title="' + pro_value+ '"><input type="checkbox" onclick="manucheck(this);" value="' + pro_value + '" class="checkinput" name="pageItem" /></td>';
            }else{
                pro_value = pageList[i][key] == null? '' : pageList[i][key] === true ? '是' : pageList[i][key] === false ? '否' : pageList[i][key];
                partsList += '<td title="' + pro_value.replace(/<br>/g,'&#10;') + '">' + pro_value + '</td>' ;
            }
        }
        var operation = '';
        if(btn != null && btn != ""){
            operation='<td class="operation">';
            if(btn.indexOf("E")>-1){
                operation+='<i onclick="edit_func('+pageList[i][ID_FIELD]+');" class="Edit content_current edit_btn edit_action" title="编辑"></i>';
            }
            if(btn.indexOf("D")>-1){
                operation+='<i onclick="delete_func('+pageList[i][ID_FIELD]+');" class="Del content_current delete_btn del_action" title="删除"></i>';
            }
            if(btn.indexOf("S")>-1){
                operation+='<i onclick="see_func('+pageList[i][ID_FIELD]+');" class="See content_current see_btn" title="查看"></i>';
            }
            if(btn.indexOf("R")>-1){
                operation+='<i onclick="rela_func('+pageList[i][ID_FIELD]+');" class="relation content_current rela_btn" title="关系绑定"></i>';
            }
            if(btn.indexOf("P")>-1){
                operation+='<i onclick="preview_func('+pageList[i][ID_FIELD]+');" class="Preview content_current" title="预览结果"></i>';
            }
            if(btn.indexOf("B")>-1){
                operation+='<i onclick="runexec_func('+pageList[i][ID_FIELD]+');" class="avliable content_current" title="运行"></i></td>';
            }
        }
        partsList = '<tr ID="'+pageList[i]["ID"]+'" data=\''+JSON.stringify(pageList[i])+'\'>'+checkId+partsList+operation+'</tr>';        //添加到表格中
        $(partsList).appendTo("#pageTable");
    }

    hideBtn();

    //处理footer 分页
    var totalCount = pageData.totalCount;
    var pageSize = pageData.pageSize;
    var totalPage = pageData.totalPage;
    var pageNo = pageData.pageNo;
    dealFooterPage(totalCount, pageSize, totalPage, pageNo);
}
/**
 * @desc 处理分页统一方法
 * @author huangjc
 * @param pageData pageData.pageList 分页数据,pageData.title 表头数据
 * @param btn 定制按钮
 */
function unifiedPaging(pageData,btn){
	//清空table下数据
	$("#pageTable").html("");
	$("#pageTitle").html("");
	//获取信息
	var pageList = pageData.pageList;
	var pageTitle = pageData.title;
	//拼接表头
	var tableTitle = '';
	for(var key in pageTitle){
		//如果不是ID属性则拼接，ID在页面不显示
	    if(key !=="ID"){
	    	tableTitle += '<th class="control-width">' +((pageTitle[key] == undefined || pageTitle[key] == null) ? '' : pageTitle[key])+ '</th>';
	    }
	} 
	if(btn != null && btn != ""){
		if(btn == "none"){
			tableTitle = '<tr><th class="checkwidth control-width"><input type="checkbox" onclick="selectAll(this);" class="checkAll" title="全选"/></th>' +tableTitle+ '</tr>';
		}else{
			tableTitle = '<tr><th class="checkwidth control-width"><input type="checkbox" onclick="selectAll(this);" class="checkAll" title="全选"/></th>' +tableTitle+ '<th class="operation control-width" style="width:150px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;操&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;作&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th></tr>';
		}
	}else{
		tableTitle = '<tr><th class="checkwidth control-width"><input type="checkbox" onclick="selectAll(this);" class="checkAll" title="全选"/></th>' +tableTitle+ '<th class="operation control-width" style="width:150px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;操&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;作&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th></tr>';
	}
	//添加到表头中
	$(tableTitle).appendTo("#pageTitle");
	
	//拼接具体数据
	for (var i = 0; i < pageList.length; i++) {
		//表格内容
		var partsList = '';
		//选择框
		var checkId = '';
		
		var Id;
		
		for(key in pageTitle){
			if(key == "ID"){
				var id = pageTitle[key];
				Id = pageList[i][id];
				checkId = '<td class="checkNot" title=' + (pageList[i][id] == null ? '' : pageList[i][id]) + '><input type="checkbox" onclick="manucheck(this);" value="' + pageList[i][id] + '" class="checkinput" name="pageItem" /></td>';
			}else{
				partsList += '<td title=' + ((pageList[i][key] == null || pageList[i][key] == undefined )? '' : pageList[i][key] === true ? '是' : pageList[i][key] === false ? '否' : "\'"+pageList[i][key]+"\'").replace(/<br>/g,'&#10;') + '>' + ((pageList[i][key] === null || pageList[i][key] == undefined) ? '' : pageList[i][key] === true ? '是' : pageList[i][key] === false ? '否' : pageList[i][key]) + '</td>' ;
			}
		}
		var operation = '<td class="operation">' +
            '<i class="Edit content_current edit_btn edit_action" title="编辑"></i>' +
            '<i class="Del content_current delete_btn del_action" title="删除"></i></td>';
		if(btn != null && btn != ""){
			//修改，删除，关联，查看
			if(btn == "relation"){
				operation = '<td class="operation">' +
                    '<i class="Edit content_current edit_btn edit_action" title="编辑"></i>' +
                    '<i class="relation content_current rela_btn" title="关系绑定"></i>' +
                    '<i class="See content_current see_btn" title="查看"></i>' +
                    '<i class="Del content_current delete_btn del_action" title="删除"></i>' +
                    '</td>';
			}
			//修改，关联，查看
			if(btn == "resourceList"){
				operation = '<td class="operation">' +
                    '<i class="Edit content_current edit_btn edit_action" title="编辑"></i>' +
                    '<i class="relation content_current rela_btn" title="关系绑定"></i>' +
                    '<i class="See content_current see_btn" title="查看"></i>'+
                    '</td>';
			}
			//资源视图
			if(btn == "bzResource"){
				operation = '<td class="operation">' +
                    '<i class="Edit content_current edit_btn edit_action" title="编辑"></i>' +
                    '<i class="relation content_current rela_btn" title="关系绑定"></i>' +
                    '<i class="See content_current see_btn" title="查看"></i>'+
                    '<i class="barCode content_current barCode_btn" title="生成二维码"></i></td>';
			}
			if(btn == "queryCustom"){
				operation = '<td><i class="Edit content_current" title="编辑" onClick="edit('+pageList[i].customQueryId+');"></i>' +
                    '<i class="Preview content_current" title="预览结果" onClick="preview('+pageList[i].customQueryId+')"></i></td>';
			}
			//修改，删除，查看
			if(btn == "see"){
				operation = '<td class="operation">' +
                    '<i class="Edit content_current edit_btn edit_action" title="编辑"></i>' +
                    '<i class="Del content_current delete_btn del_action" title="删除"></i>' +
                    '<i class="See content_current see_btn" title="查看"></i></td>';
			}
            //修改，删除，查看
			if(btn == "agent"){
				operation = '<td class="operation">' +
                    '<i class="Edit content_current edit_btn edit_action" title="编辑"></i>' +
                    '<i class="Del content_current delete_btn del_action" title="删除"></i>' +
                    '<i class="See content_current see_btn" title="任务列表"></i></td>';
			}
			//查看
			if(btn == "onlySee"){
				operation = '<td class="operation"><i class="See content_current see_btn" title="查看"></i></td>';
			}
			//编辑，删除，服务器列表，路由列表
			if(btn == "address"){
				operation = '<td class="operation"><i class="Edit content_current edit_btn edit_action" title="编辑"></i><i class="Del content_current delete_btn del_action" title="删除"></i><i class="Server content_current address_server_btn edit_action" title="服务器列表"></i><i class="Route content_current address_route_btn edit_action" title="路由列表"></i></td>';
			}
            //实时执行 任务执行列表中添加
            if(btn == "realtimeExec"){
                operation = '<td class="operation">' +
                    '<i class="content_current Edit edit_btn edit_action" title="编辑"></i>' +
                    '<i class="Del content_current delete_btn del_action" title="删除"></i>' +
                    '<i class="See content_current see_btn" title="结果预览"></i>' +
                    '<i class=" content_current Server" title="命令执行"></i>' +
                    '<i class="avliable content_current" title="运行"></i></td>';
            }
            if(btn=='radarResource'){
                operation = '<td>'+
                    '<div class="btn-group">'+
                        '<a class="btn btn-small btn-success dropdown-toggle" data-toggle="dropdown" >'+
                            'Action'+
                            '<span class="caret"></span>'+
                        '</a>'+
                        '<ul class="dropdown-menu">'+
                            '<li><a href="#" classes="'+pageList[i].classes+'" class="strategyBtn">采集策略</a></li>'+
                            '<li><a href="#" class="collectBtn">采集指标</a></li>'+
                            '<li><a href="#" class="configureBtn">配置</a></li>'+
                            '<li><a href="#" class="contactsBtn">联系人组</a></li>'+
                        '</ul>'+

                    '</div>'+
                '</td>';
            }
			//没有任何操作
			if(btn == "none"){
				operation = '';
			}
		}
		partsList = '<tr ID="'+Id+'">'+checkId+partsList+operation+'</tr>'
		//添加到表格中
		$(partsList).appendTo("#pageTable");
	}
	
	    hideBtn();
		//绑定编辑按钮
	  $('.edit_btn').click(function(){
	      edit_func(this);
	  });
	  	//绑定删除按钮
	  $('.delete_btn').click(function(){
	      delete_func(this);
	  });
	  
	  if(btn != null && btn != ""){
			if(btn == "relation"||btn == "resourceList"){
				$(".rela_btn").click(function(){
					rela_btn(this);
				  });
				$(".see_btn").click(function(){
					see_btn(this);
				  });
			}else if(btn == "see"){
				$(".see_btn").click(function(){
					see_btn(this);
				  });
			}else if(btn == "onlySee"){
				$(".see_btn").click(function(){
					see_btn(this);
				  });
			}else if(btn == "address"){
				$(".address_server_btn").click(function(){
					address_server_btn(this);
				});
				$(".address_route_btn").click(function(){
					address_route_btn(this);
				});
			}else if(btn == "realtimeExec"){
                $(".Server").click(function(){
                    runexec_btn(this);
                });
                $(".see_btn").click(function(){
					see_btn(this);
				});
            }else if(btn == "agent"){
                $(".see_btn").click(function(){
                    agentTask_btn(this);
                });
            }else if (btn == "bzResource") {
                $(".rela_btn").click(function(){
                    rela_btn(this);
                });
                $(".see_btn").click(function(){
                    see_btn(this);
                });
                $(".barCode_btn").click(function () {
                    create_QRCode(this);
                })
            }
		}
	
	//处理footer 分页
    var totalCount = pageData.totalCount;
    var pageSize = pageData.pageSize;
    var totalPage = pageData.totalPage;
    var pageNo = pageData.pageNo;
    dealFooterPage(totalCount, pageSize, totalPage, pageNo);
}
/**
 * 全选框选择
 */
function selectAll(field){

    if(field.checked){
        //标签属性是true或false的，使用prop()，其他的可以使用attr()
        $('.content_table .checkinput').prop('checked','checked');
        $(field).attr('title','取消全选')
    }else{
        $('.content_table .checkinput').removeAttr('checked');
        $(field).attr('title','全选')
    }
}
/**
 * 同步全选框
 */
function manucheck(field){
    if(field.checked==false){
        $(".checkAll").removeAttr("checked");
    }else{
        var flagCheckAll = true;
        $("input[name='pageItem']").each(function(){
            if($(this).attr("checked")!='checked'){
                flagCheckAll=false;
            }
        });
        if(flagCheckAll){
            $(".checkAll").attr("checked","checked");
        }
    }
}
/**
 * 使用说明
 * 1 分页 jsp 引入 common/jsp/footer_pager.jsp   <%@ include file="/common/jsp/footer_pager.jsp"%>
 * 2 js 中定义paging 方法  中table填充
 * 3 调用 dealFooterPage
 * 处理footer中 显示条数 和 分页信息
 * @param totalCount
 * @param pageSize
 * @param totalPage
 * @param pageNo
 * 需要提供一个分页的方法 paging  调用做分页填充table信息
 */
function dealFooterPage(totalCount,pageSize,totalPage,pageNo){
    if(totalCount===null || totalCount===''||totalCount===undefined ){
        //sysEcho("totalCount:"+totalCount);
        return;
    }
    if(pageSize===null || pageSize==='' ||pageSize===undefined){
        //sysEcho("pageSize:"+pageSize);
        return;
    }
    if(totalPage===null || totalPage==='' ||totalPage===undefined){
        //sysEcho("totalPage:"+totalPage);
        return;
    }
    if(pageNo===null || pageNo===''|| pageNo===undefined){
        //sysEcho("pageNo:"+pageNo);
        return;
    }

    $("#pageMenu").html("");
    var partsPageList=
        '<div class="table-actions" style="float:left;" >'+
        '展示条数:'+
        '<select id="pageSize"  style="width:60px;">'+
        '<option value="1" '+(pageSize==1?"selected":"")+'>1</option>'+
        '<option value="10" '+(pageSize==10?"selected":"")+'>10</option>'+
        '<option value="15" '+(pageSize==15?"selected":"")+'>15</option>'+
        '<option value="20" '+(pageSize==20?"selected":"")+'>20</option>'+
        '<option value="25" '+(pageSize==25?"selected":"")+'>25</option>'+
        '<option value="30" '+(pageSize==30?"selected":"")+'>30</option>'+
        '<option value="35" '+(pageSize==35?"selected":"")+'>35</option>'+
        '<option value="40" '+(pageSize==40?"selected":"")+'>40</option>'+
        '<option value="50" '+(pageSize==50?"selected":"")+'>50</option>'+
        '<option value="100" '+(pageSize==100?"selected":"")+'>100</option>'+
        '<option value="200" '+(pageSize==200?"selected":"")+'>200</option>'+
        '<option value="500" '+(pageSize==500?"selected":"")+'>500</option>'+
        '</select>'+
        '共'+totalCount+'条记录'+
        '</div>'+
        '<div class="pagination" style="float:right">'+
        '<ul>';
    if(pageNo!==1 && pageNo!==0){
        partsPageList+='<li>'+(totalPage==1?"":'<a href="javascript:;" onclick="paging(1)">首页</a>')+'</li>'+
            '<li>'+(totalPage==1?"":'<a href="javascript:;" onclick="paging('+((pageNo-1)>1?(pageNo-1):1)+')">上一页</a>')+'</li>';
    }
    if(pageNo<=2){
        for(var i=1;i<=(totalPage>5?5:totalPage);i++){
            partsPageList=partsPageList+'<li '+(pageNo==i?"class=active":"")+'><a href="javascript:;" onclick=paging('+i+')>'+i+'</a>'+(pageNo==i?'<input type="hidden" id="currentPage" value="'+i+'"/>':"")+'</li>';
        }
    }else if((pageNo+2)>totalPage){
        for(var i=(totalPage-4>0?totalPage-4:1);i<=totalPage;i++){
            partsPageList=partsPageList+'<li '+(pageNo==i?"class=active":"")+'><a href="javascript:;" onclick=paging('+i+')>'+i+'</a>'+(pageNo==i?'<input type="hidden" id="currentPage" value="'+i+'"/>':"")+'</li>';
        }
    }else{
        for(var i=(pageNo>2?2:pageNo);i>=1;i--){
            partsPageList=partsPageList+'<li><a href="javascript:;" onclick="paging('+(pageNo-i)+')">'+(pageNo-i)+'</a></li>';
        }
        partsPageList=partsPageList+'<li class="active"><a href="javascript:;" onclick="paging('+pageNo+')">'+pageNo+'</a><input type="hidden" id="currentPage" value="'+pageNo+'"/></li>';
        for(var j=pageNo+1;j<=(totalPage<(pageNo+2)?totalPage:(pageNo+2));j++){
            partsPageList=partsPageList+'<li><a href="javascript:;" onclick="paging('+j+')">'+j+'</a></li>';
        }
    }
    if(totalPage!=pageNo){
        partsPageList=partsPageList+'<li>'+(totalPage==1?"":'<a href="javascript:;" onclick="paging('+((pageNo+1)<(totalPage)?(pageNo+1):(totalPage))+')">下一页</a>')+'</li>'+
            '<li>'+(totalPage==1?"":'<a href="javascript:;" onclick="paging('+(totalPage)+')">尾页</a>')+'</li>';
    }
    partsPageList=partsPageList+  '</ul></div>';
    $(partsPageList).appendTo("#pageMenu");

    /**
     * 选择一页显示的页数跳转页面
     */
    $("#pageSize").change(function(){
        paging(1);
    });
    /**
     * 添加loading图标
     * @param aimDiv 遮盖
     * @param desc
     */
    function addLoadingDiv(path,aimDiv,desc){
        var img = $("<div id=\"progressImgage\"><img style='width:60px;margin-left:120px;' src=\""+path
            +"/images/loading/ajax-load.gif\" /><div style='width:300px;text-align: center;font-size:16px;margin-top:10px'>"+desc+"</div></div>"); //Loading小图标
        var mask = $("<div id=\"maskOfProgressImage\"></div>").addClass("mask"); //Div遮罩
        var PositionStyle = "absolute";
        //是否将Loading固定在aimDiv中操作,否则默认为全屏Loading遮罩
        if (aimDiv != null && aimDiv != "" && aimDiv != undefined) {
            $(aimDiv).css("position", "relative").append(img).append(mask);
            PositionStyle = "absolute";
        }
        else {
            $("body").append(img).append(mask);
        }
        img.css({
            'width':'300px',
            'position':'absolute',
            'top':'40%',
            'left':'50%',
            'margin-left':'-150px',
            "z-index": "2000"
        })
        mask.css({
            "position": PositionStyle,
            "top": "0",
            "right": "0",
            "bottom": "0",
            "left": "0",
            "z-index": "1000",
            "background-color": "#000000",
            'opacity':'0.1'
        });
    }
    /**
     * 去除loading图标
     */
    function removeLoadingDiv(){
        $("#progressImgage").remove();
        $("#maskOfProgressImage").remove();
    }
}

/**
 * -----------------------------------------<<<分页方法<<<--------------------------
 */
/**
 * 重写Ajax操作,做成通用Loading操作
 * @param path 项目目录
 * @param options ajax 参数
 * @param aimDiv  局部
 * @param desc 描述细信息
 */
$.ajax2 = function (path,options, aimDiv,desc) {
    if(desc==null){
        desc=""
    }
    var img = $("<div id=\"progressImgage\" style='width:300px;'><img style='width:60px;margin-left:120px;' src=\""+path
        +"/images/loading/ajax-load.gif\" /><div style='width:300px;text-align: center;font-size:16px;margin-top:10px'>"+desc+"</div></div>"); //Loading小图标
    var mask = $("<div id=\"maskOfProgressImage\"></div>").addClass("mask").addClass("hide"); //Div遮罩
    var PositionStyle = "absolute";
    //是否将Loading固定在aimDiv中操作,否则默认为全屏Loading遮罩
    if (aimDiv != null && aimDiv != "" && aimDiv != undefined) {
        $(aimDiv).css("position", "relative").append(img).append(mask);
        PositionStyle = "absolute";
    }
    else {
        $("body").append(img).append(mask);
    }
    img.css({
        "z-index": "2000",
        "display": "none"
    })
    mask.css({
        "position": PositionStyle,
        "top": "0",
        "right": "0",
        "bottom": "0",
        "left": "0",
        "z-index": "1000",
        "background-color": "#000000",
        "display": "none"
    });
    var complete = options.complete;
    options.complete = function (httpRequest, status) {
        img.hide();
        mask.hide();

        if (complete) {
            complete(httpRequest, status);
        }
    };

    img.show().css({
        "position": PositionStyle,
        "top": "40%",
        "left": "50%",
        "margin-top": function () { return -1 * img.height() / 2; },
        "margin-left": function () { return -1 * img.width() / 2; }
    });
    mask.show().css("opacity", "0.1");
    $.ajax(options);
};
/**
 * 将日期类型对象转换为字符串
 */
var formatDateTime = function (date) {  
    var y = date.getFullYear();  
    var m = date.getMonth() + 1;  
    m = m < 10 ? ('0' + m) : m;  
    var d = date.getDate();  
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours(); 
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    minute = minute < 10 ? ('0' + minute) : minute;  
    var s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+s;
};

/**
 * ----------------------------------------------自动填充option方法----------------------start
 */
/**
 * 
 * 快速查询填充option 码表
 */
function easySelect(){
	//拼接需要查找码表   type
	var  selectType='';
	$("select[autoSelect]").each(function(){
		selectType=selectType+$(this).attr("autoSelect")+",";
	}); 
	selectType=selectType.substring(0,selectType.length-1);	
	//ajax请求  查找需要的 码表代码信息
	if(selectType!=''){	
	    $.ajax({
	        url:basePath+"/sys/lookup_management/easySelect.do",
	        type:"post",
	        dataType: 'json',
	        data:{
	            "selectType":selectType
	        },
	        error:function(data){
	        	layer.msg('出错了！！',{time:2000});
	        },
	        success:function(result){      	
	        	var codeSelect=result.codeSelect;//获取code总集合
	        	for (var i = 0; i < codeSelect.length; i++) {       		
					var codelist=codeSelect[i];
					var  type=codeSelect[i][0].lookupType;
					//遍历查找 填充
					$("select[autoSelect]").each(function(){
						//动态装载option
		        		if($(this).attr("autoSelect") == type ){
		        			var appendOption="";
		        			for (var j = 0; j < codelist.length; j++) {
								var sysLookupcode=codelist[j];	
								appendOption=appendOption+"<option value='"+sysLookupcode.cdeValue+"' >"+sysLookupcode.cdeName+"</option>";
							}
		        			$(this).append(appendOption);
		        		}
		        		
		        	});
				}
	         
	        }
	    });
	}

}

function easySelect2(){
	//拼接需要查找码表   type
	var  selectType='';
	$("select[autoSelect]").each(function(){
		selectType=selectType+$(this).attr("autoSelect")+",";
	}); 
	selectType=selectType.substring(0,selectType.length-1);	
	//ajax请求  查找需要的 码表代码信息
	if(selectType!=''){	
	    $.ajax({
	        url:basePath+"/sys/lookup_management/easySelect.do",
	        type:"post",
	        dataType: 'json',
	        data:{
	            "selectType":selectType
	        },
	        error:function(data){
	        	layer.msg('出错了！！',{time:2000});
	        },
	        success:function(result){      	
	        	var codeSelect=result.codeSelect;//获取code总集合
	        	for (var i = 0; i < codeSelect.length; i++) {       		
					var codelist=codeSelect[i];
					var  type=codeSelect[i][0].lookupType;
					//遍历查找 填充
					$("select[autoSelect]").each(function(){
						//动态装载option
		        		if($(this).attr("autoSelect") == type ){
		        			var appendOption="";
		        			for (var j = 0; j < codelist.length; j++) {
								var sysLookupcode=codelist[j];	
								appendOption=appendOption+"<option value='"+sysLookupcode.lookupCode+"' >"+sysLookupcode.cdeName+"</option>";
							}
		        			$(this).append(appendOption);
		        		}
		        		
		        	});
				}
	         
	        }
	    });
	}

}
/**
 * 
 * 获取当前项目名   局限性 访问地址未  192.169.20.217  没有项目名称的  获取不正确
 */
function getBasePath() {
    // 获取主机地址之后的目录，如： /ssm/index.jsp
    var pathName = window.document.location.pathname;
    // 获取带"/"的项目名，如：/ssm
    var basePath = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    return basePath;
}
/**
 * ----------------------------------------------数据校验方法----------------------start
 */

/**
 * 
 * 初始化check数据类型的文本框进行绑定blur方法;
 */
function  initCheckdata() {	
	var  checkdata= $("*[checkData]:visible");//获取需要校验数据的input选择框
	checkdata.on("blur",checkValues);	
}
/**
 * 
 * 显示校验
 */
function  checkData(){ warn='info'
	$("*[checkData]:visible").blur();
	if($(".check_class").length>0  ||$("*[warn='info']").length>0){
		layer.msg("红色区域数据异常，请检查录入信息");
		return false;
	}
	return true;
}
/**
 * 
 * 文本框校验
 * 
 */
function  checkValues(event) {
	    var dom=event.target;
		var checkType=$(dom).attr("checkData");
		var checkarray=checkType.split('_');
		checkType=checkarray[0];
		var checkWarning=false;
		var warningMessage='';
		if(checkarray.length==2){
			checkWarning=true;
			warningMessage=checkarray[1]
		}
		$(dom).removeClass("check_class"); 
		$(dom).attr("title","");
		removeWarning(dom);
		switch (checkType) {
		case "NotNull":
			checksNotNull(dom,checkWarning,warningMessage);
			break;
        case "Num":
        	checksNumber(dom,checkWarning,warningMessage);
			break;
        case "NumNotNull":
        	checksNumberNotNull(dom,checkWarning,warningMessage);
			break;
        case "PInt":
        	checksPInt(dom,checkWarning,warningMessage);
			break;
        case "Phone":
        	checksPhoneNull(dom,checkWarning,warningMessage);
			break; 
        case "Ip":
        	checksIP(dom,checkWarning,warningMessage);
			break;
        case "IpNotNull":
        	checksIPNotNull(dom,checkWarning,warningMessage);
			break;
        case "Code":
        	checksCode(dom,checkWarning,warningMessage);
			break;
        case "CodeNotNull":
        	checksCodeNotNull(dom,checkWarning,warningMessage);
			break;
        case "Num>": 
        	checksNumBig(dom,checkWarning,warningMessage);
			break;
        case "MailNotNull":
        	checksMailNotNull(dom,checkWarning,warningMessage);
			break;
        case "IpNotNullMore":	
			checksIPNotNullMore(dom,checkWarning,warningMessage);
			break;
		default:
			break;
		}				
	}



/**
 * 
 * 校验正整数且大于数
 * 
 */

function checksNumBig(field,isWarning,warningMessage) {
	
	var   num=$(field).attr("num");
	
    var g = /^[1-9]*[1-9][0-9]*$/;
    var  message="必须大于"+num;
	  if(""!=warningMessage){
		  message=warningMessage;
	  }
	if(!(g.test($(field).val()))|| ($(field).val()>num)){
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		if(isWarning){
			showWarning(field,message)
		}
	}else{
		$(field).removeClass("check_class"); 
		$(field).attr("title","");
	}
	
	
}
/**
 * 
 * 校验正整数
 * 
 */

function checkPInts(field,isWarning,warningMessage) {
    var g = /^[1-9]*[1-9][0-9]*$/;
    var  message="必须为正整数";
	  if(""!=warningMessage){
		  message=warningMessage;
	  }
	if(!g.test($(field).val())){
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		if(isWarning){
			showWarning(field,message)
		}
	}else{
		$(field).removeClass("check_class"); 
		$(field).attr("title","");
	}
}
/**
 * 数字验证
 */
function checksNumber(field,isWarning,warningMessage){
	
	  var  message="必须为数字";
	  if(""!=warningMessage){
		  message=warningMessage;
	  }
	  
	if(isNaN(field.value)&&(field.value!='')){
		
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		if(isWarning){
			showWarning(field,message)
		}
	}else{
		$(field).removeClass("check_class"); 
		$(field).attr("title","");
	}
}

/**
 * 数字验证 非空
 */
function checksNumberNotNull(field,isWarning,warningMessage){
	
	  var  message="必须为数字";
	  if(""!=warningMessage){
		  message=warningMessage;
	  }
	  
	if(isNaN(field.value)||(field.value=='')){
		
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		if(isWarning){
			showWarning(field,message)
		}
	}else{
		$(field).removeClass("check_class"); 
		$(field).attr("title","");
	}
}
/**
 * 非空验证
 * @param field 表单元素
 */
function checksNotNull(field,isWarning,warningMessage){
	
	  if(""==field.value){
		  var  message="不能为空";
		  if(""!=warningMessage){
			  message=warningMessage;
		  }		 
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		if(isWarning){
			showWarning(field,message)
		}
	}else{
		$(field).removeClass("check_class"); 
		$(field).attr("title","");
	}
}
/**
 * 编码验证,可以为空
 * @param field 表单元素
 */
function checksCode(field,isWarning,warningMessage){
	 var  message="编码必须为数字字母下划线！";
	  if(""!=warningMessage){
		  message=warningMessage;
	  }
	if(""==field.value){
	}else{
		var reg=/^[\w_\s]+$/;
		if(!reg.test($.trim(field.value))){
			$(field).addClass("check_class"); 
			$(field).attr("title",message);
			if(isWarning){
				showWarning(field,message)
			}
		}else{
			$(field).removeClass("check_class"); 
			$(field).attr("title","");
		}
	}
}

/**
 * 校验手机号,电话号码
 * @param field 表单元素
 */
function checksPhoneNull(field,isWarning,warningMessage){
	
	if(""==field.value){
		  var  message="不能为空";
		  if(""!=warningMessage){
			  message=warningMessage;
		  }
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		
		if(isWarning){
			showWarning(field,message)
		}
	}else{
		var reg = /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/;
		var  message="电话格式不正确！";
		  if(""!=warningMessage){
			  message=warningMessage;
		  }
		if(!reg.test($.trim(field.value))){
			$(field).addClass("check_class"); 
			$(field).attr("title",message);
			if(isWarning){
				showWarning(field,message)
			}
		}else{
			$(field).removeClass("check_class"); 
			$(field).attr("title","");
		}
	}
}


/**
 * 校验邮箱且不能为空
 * @param field 表单元素
 */
function checksMailNotNull(field,isWarning,warningMessage){
	
	if(""==field.value){
		  var  message="不能为空";
		  if(""!=warningMessage){
			  message=warningMessage;
		  }
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		
		if(isWarning){
			showWarning(field,message)
		}
	}else{
		var reg = /^[A-Za-z\d]+([\-_\.][A-Za-z\d]+)*@([A-Za-z\d]+[\-\.])+[A-Za-z\d]{2,5}$/;
		var  message="邮箱格式错误！";
		  if(""!=warningMessage){
			  message=warningMessage;
		  }
		if(!reg.test($.trim(field.value))){
			$(field).addClass("check_class"); 
			$(field).attr("title",message);
			if(isWarning){
				showWarning(field,message)
			}
		}else{
			$(field).removeClass("check_class"); 
			$(field).attr("title","");
		}
	}
}
/**
 * 编码验证,且不为空
 * @param field 表单元素
 */
function checksCodeNotNull(field,isWarning,warningMessage){

	if(""==field.value){
		 var  message="不能为空";
		  if(""!=warningMessage){
			  message=warningMessage;
		  }
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		if(isWarning){
			showWarning(field,message)
		}
	}else{
		var reg=/^[\w_\s]+$/;
		if(!reg.test($.trim(field.value))){
			 var  message="编码必须为数字字母下划线！";
			  if(""!=warningMessage){
				  message=warningMessage;
			  }
			$(field).addClass("check_class"); 
			$(field).attr("title",message);
			if(isWarning){
				showWarning(field,message)
			}
		}else{
			$(field).removeClass("check_class"); 
			$(field).attr("title","");
		}
	}
}
/**
 * 判断ip地址的合法性，可以为空
 * 
 */
function checksIP(field,isWarning,warningMessage){

	if(""==field.value){
	}else{
	    var reg=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
	    var  message="IP地址格式错误";
		  if(""!=warningMessage){
			  message=warningMessage;
		  }
		if(!reg.test($.trim(field.value))){
			$(field).addClass("check_class"); 
			$(field).attr("title",message);
			if(isWarning){
				showWarning(field,message)
			}
		}else{
			$(field).removeClass("check_class"); 
			$(field).attr("title","");
		}
	}
}

/**
 * 判断多个ip地址，号分割的合法性
 * 
 */
function checksIPNotNullMore(field,isWarning,warningMessage){

	if(""==field.value){
		  var  message="不能为空";
		  if(""!=warningMessage){
			  message=warningMessage;
		  }
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		if(isWarning){
			showWarning(field,message)
		}
	}else{
	    var reg=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
	    //多个IP 用，号分割
	     var array= field.value.split(',');
	     for (var int = 0; int < array.length; int++) {			
	    	 if(!reg.test($.trim(array[int]))){
				 var  message="ip地址错误";
				  if(""!=warningMessage){
					  message=warningMessage;
				  }
				$(field).addClass("check_class"); 
				$(field).attr("title",message);
				if(isWarning){
					showWarning(field,message)
				}
				break;
			}
		}
	 	$(field).removeClass("check_class"); 
		$(field).attr("title","");	
	
	}
}

/**
 * 判断ip地址的合法性
 * 
 */
function checksIPNotNull(field,isWarning,warningMessage){

	if(""==field.value){
		  var  message="不能为空";
		  if(""!=warningMessage){
			  message=warningMessage;
		  }
		$(field).addClass("check_class"); 
		$(field).attr("title",message);
		if(isWarning){
			showWarning(field,message)
		}
	}else{
	    var reg=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
		if(!reg.test($.trim(field.value))){
			 var  message="不能为空";
			  if(""!=warningMessage){
				  message=warningMessage;
			  }
			$(field).addClass("check_class"); 
			$(field).attr("title",message);
			if(isWarning){
				showWarning(field,message)
			}
		}else{
			$(field).removeClass("check_class"); 
			$(field).attr("title","");
		}
	}
}
/**
 * 
 * @param field 表单元素
 * @param name 属性名称
 * @param ismust 是否必填
 * @param reg 正则表达式
 * @param msg 提示信息
 * @param maxlength 最大长度
 */
function checksReg(field,name,ismust,reg,msg,maxlength){
	if(""==msg||null==msg){
		msg="数据不合法!";
	}
	if(ismust){
		if($.trim(field.value)==""){
			$("#"+field.id).attr("style","border-color:red;");
			$("#"+field.id).attr("title",name+"不能为空！");
		}else{
			$("#"+field.id).attr("style","border-color:;");
			$("#"+field.id).removeAttr("title");
			if(""!=reg&&null!=reg){
				if(!reg.test($.trim(field.value))){
					$("#"+field.id).attr("style","border-color:red;");
					$("#"+field.id).attr("title",""+name+":"+msg);
				}else{
					if(field.value.length>maxlength){
						$("#"+field.id).attr("style","border-color:red;");
						$("#"+field.id).attr("title","输入长度过长，请调整！");
					}else{
						$("#"+field.id).attr("style","border-color:;");
						$("#"+field.id).removeAttr("title");
					}
				}
			}
			
		}
	}else{
		if(""==$.trim(field.value)){
			
		}else{
			$("#"+field.id).attr("style","border-color:;");
			$("#"+field.id).removeAttr("title");
			if(""!=reg){
				if(!reg.test($.trim(field.value))){
					$("#"+field.id).attr("style","border-color:red;");
					$("#"+field.id).attr("title",""+name+":"+msg);
				}else{
					if(field.value.length>maxlength){
						$("#"+field.id).attr("style","border-color:red;");
						$("#"+field.id).attr("title","输入长度过长，请调整！");
					}else{
						$("#"+field.id).attr("style","border-color:;");
						$("#"+field.id).removeAttr("title");
					}
				}
			}
		}
	}
}


/**
 *@desc 判断输入是否包含空格
 *@return 
 *	true-含有空格   
 *	false-不包含 
 */
var $isSpace = function(name){
	var re = /\s/;	
	return re.test(name);
} 

/**
 *添加Warning信息
 * 	  
 */
function showWarning(field,message) {
	var  warning="<span id='"+field.id+"Warning' class='redbtn' warn='info' >"+message+"</span>";
	$(field).after(warning);
}
/**
 *移除Warning信息
 * 	  
 */
function removeWarning(field) {
	$("#"+field.id+"Warning").remove();
}
/**
 * 移除全部的Warning信息
 */
function  removeAllWarning(){
	var  checkdata= $("*[checkData]:visible");//获取需要校验数据的input选择框
	checkdata.attr("style","border-color:;");
	checkdata.removeAttr("title");
	$("*[warn]").remove();
} 

/**
 * --------------------------------------->>>自动查询列表<<<<---------------------------------------------------
 * 
 */

function easyQuery(Initdata,parm,querydata) {
	
	
	initQueryLine(Initdata,parm,querydata);	
	easyQueryAjax(Initdata,parm,querydata);
	
}


/**初始化列表数组
 * @param dataJson
 * @param divName  
 */
function initQueryLine(Initdata,parm,querydata){
	
	 var dataJson=Initdata
	 var divID=parm.divID
	if(dataJson==null||dataJson==''){
		return;
	}
    if(divID==null||divID==''){
    	return;
	}
    $("#"+divID).html("");
    
    //处理  参数
    var  strInitdata=JSON.stringify(Initdata).replace(/\"/g,"'");
    var  strparm=JSON.stringify(parm).replace(/\"/g,"'");
    var  strquerydata=JSON.stringify(querydata).replace(/\"/g,"'");
    //初始化  div中的列表体
    var  divTable="<div  id='"+divID+"tablebox' class='tablebox' style='overflow-x: auto;'>" +
    		       "<table id='"+divID+"table' class='table table-striped table-bordered table-hover table-ellipsis details'>"+
				   "<thead id='"+divID+"pageTitle'></thead>"+             			
                 	"<tbody id='"+divID+"pageTable'></tbody>" +
                  "</table></div>" 
     //初始化页脚            	
    var  divTableEnd='<div id="'+divID+'pageMenu" style="width:auto;height:30px;"  initdata="'+strInitdata+'"  parm="'+strparm+'"  querydata="'+strquerydata+'" ></div>';
    $("#"+divID).append(divTable+divTableEnd);
   
    //初始化表头
    var divHead="<tr>";  
   for (var  i= 0;  i< dataJson.length; i++) {
	   //是否需要复选框
	     if(i==0){
	    	 if(dataJson[0].name=="checkBox"){
	    		 if(dataJson[0].show==false){
	    			 divHead=divHead+"<th code='" + dataJson[i].code + "' id='"+divID+"checkBox'   class='checkwidth'  style='display:none' ><input type='checkbox' divID='"+divID+"'  onclick='newSelectAll(this);'  class='checkinput'  title='全选'/></th>"; 
	    		 }else{
	    			 divHead=divHead+"<th code='" + dataJson[i].code + "' id='"+divID+"checkBox'   class='checkwidth'><input type='checkbox' divID='"+divID+"'  onclick='newSelectAll(this);' class='checkinput' title='全选'/></th>";
	    		 }	    		 
	    	 }else{
	    		    var    width='';
		    	    if(dataJson[i].width==''||dataJson[i].width==null){
		    	    	   width="style='width:"+dataJson[i].width+"%'";	
		    	    }
		            divHead += "<th  class='control-width'  code='" + dataJson[i].code + "' "+width+" >" + dataJson[i].name + "</th>" ;	    		 
	    	 }
	     }else if(i==(dataJson.length-1)){
	    	 if(dataJson[dataJson.length-1].name=="操作"){
	    		 divHead=divHead+"<th   code='" + dataJson[i].code + "'  id='"+divID+"operation' class='operation' style='width:150px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;操&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;作&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th></tr>"
	    	 }else{
	    		 var    width='';
		    	    if(dataJson[i].width==''||dataJson[i].width==null){
		    	    	   width="style='width:"+dataJson[i].width+"%'";	
		    	    }
		            divHead += "<th  class='control-width'  code='" + dataJson[i].code + "' "+width+" >" + dataJson[i].name + "</th></tr>" ;	    		 
	    	 }
	     }else{
	    	    var    width='';
	    	    if(dataJson[i].width==''||dataJson[i].width==null){
	    	    	   width="style='width:"+dataJson[i].width+"%'";	
	    	    }
	            divHead += "<th  class='control-width'  code='" + dataJson[i].code + "' "+width+" >" + dataJson[i].name + "</th>" ;
	     }	   
    }  
   divHead+="</tr>"
	   $("#"+divID+"pageTitle").append(divHead);   
};



function  easyQueryAjax(Initdata,parm,querydata){
	//设置 页面的大小   及 展示页。
	 var pageSize=10;
	 if(parm.isFooterPage==false){
		 pageSize=100; 
	 }
	 querydata.pageSize=(querydata.pageSize==null?pageSize:querydata.pageSize);
	 querydata.pageNo = (querydata.pageNo==null?1:querydata.pageNo);
	 
	 var Async=false;
	 if(parm.isAsync==true){
		 Async=true; 
	 }
	//ajax 请求方法
	    $.ajax({
	        url: parm.url,
	        type: "post",
	        dataType: 'json',
	        async: Async,
	        data: querydata,
	        error: function (data) {
	            console.log(data);
	            layer.msg(data.message,{time:2000});
	        },
	        success: function (jsons) {
	        	$("#"+parm.divID+"pageTable").html("");//清空原数据
	        	$("#"+parm.divID+"pageMenu").html("");//清空页脚
	            if(jsons.code == 500){
	                layer.msg(jsons.errorMessage);
	            }else if (jsons.code == 201){
	            	  if(parm.isWarning==false){
	            		  
	            	  }else{   
	            		  layer.msg("数据为空！");
	            		  }
	             
	            }else{
	                queryShowTable(jsons.pageData,parm.divID,Initdata);
	                //isFooterPage默认才生页脚
	                if(parm.isFooterPage==false){
	              
	                }else{
	                  NewdealFooterPage(jsons.pageData,Initdata,parm,querydata);
	                }
	                
	            }
	            //回调函数
         	     if(parm.afterQuery!=null){
         		 eval(parm.afterQuery+"()");	
         		}
	        }
	    });
	 

/**动态添加数据到目标列
 * @param date
 * @param divID
 */
}

function queryShowTable(pageData,divID,Initdata){
    //获取信息
    var pageList = pageData.pageList;
    //初始化
    var appendStr='';
    //获取操作列表 
    var operation = '';//如有操作在这里一次性取出  以减少运算次数
    if( Initdata[Initdata.length-1].name=="操作"){
    	operation=getOperation(Initdata[Initdata.length-1].code,divID);
    }
    
    //循环拼接数据
    for (var p = 0; p < pageList.length; p++) {
    	var pjson=pageList[p];
    	var appendStrTr="<tr";  
        for (var i = 0; i < Initdata.length; i++) {
        	var ijson=Initdata[i];
        	var valcode=pjson[ijson.code]==null?'':pjson[ijson.code];//对应字段值
        	if(i==0){
        		if(ijson.name=='checkBox'){
        			 if(ijson.show==false){
        					appendStrTr+=" nodeId='"+valcode+"' divID='"+divID+"'><td style='display:none' code='"+ijson.code+"' title='"+valcode+"' class='checkNot' ><input nodeId='"+valcode+"' type='checkbox'   divID='"+divID+"' class='checkinput'  onclick='manucheck(this);'    name='pageItem' /></td>";
        			 }else{
        					appendStrTr+=" nodeId='"+valcode+"' divID='"+divID+"'><td code='"+ijson.code+"' title='"+valcode+"' class='checkNot' ><input nodeId='"+valcode+"' type='checkbox'   divID='"+divID+"' class='checkinput'  onclick='manucheck(this);' name='pageItem' /></td>";
        			 }
        		
        		}else{
        			appendStrTr+=" nodeId='"+valcode+"' divID='"+divID+"'><td code='"+ijson.code+"' title='"+valcode+"'  >" + valcode + "</td>";
        		}
        	}else if(i==(Initdata.length-1)){
        		 if( ijson.name=="操作"){
        			 appendStrTr+=operation; 
        		    }else{
        		     appendStrTr+="<td code='"+ijson.code+"' title='"+valcode+"'>" + valcode + "</td>";
        		    }
        		 appendStrTr+="</tr>" 
        	}else{
        		appendStrTr+=" 	<td code='"+ijson.code+"' title='"+valcode+"'>" + valcode + "</td>";
        	}
		   
		}
        appendStr+=appendStrTr;
	}	
    $(appendStr).appendTo("#"+divID+"pageTable");
    
}
/**获取目标操作
 * @param OperationType
 * @returns {String}
 */
function getOperation(OperationType,divID){
	var operation = '';
	if(OperationType != null && OperationType != ""){
	    operation="<td class='operation'>";
	    if(OperationType.indexOf("S")>-1){
	        operation+="<i onclick='see_"+divID+"(this);' class='See content_current see_btn' title='查看'></i>";
	    }
	    if(OperationType.indexOf("B")>-1){
	        operation+="<i onclick='runexec_"+divID+"(this);' class='avliable content_current' title='运行'></i>";
	    }
	    if(OperationType.indexOf("E")>-1){
	        operation+="<i onclick='edit_"+divID+"(this);' class='Edit content_current edit_btn edit_action' title='编辑'></i>";
	    }	   	  
	    if(OperationType.indexOf("R")>-1){
	        operation+="<i onclick='rela_"+divID+"(this); ' class='relation content_current rela_btn' title='关系绑定'></i>";
	    }
	    if(OperationType.indexOf("I")>-1){
	        operation+="<i onclick='ser_"+divID+"(this); ' class='Server content_current' title='关系绑定'></i>";
	    }
	    if(OperationType.indexOf("P")>-1){
	        operation+="<i onclick='preview_"+divID+"(this);' class='Preview content_current' title='预览结果'></i>";
	    }
	    if(OperationType.indexOf("D")>-1){
	        operation+="<i onclick='del_"+divID+"(this);' class='Del content_current delete_btn del_action' title='删除'></i>";
	    }
	    if(OperationType.indexOf("G")>-1){
	        operation+="<i onclick='ign_"+divID+"(this);' class='alarmIgnore content_current' title='忽略'></i>";
	    }
	    if(OperationType.indexOf("J")>-1){
	        operation+="<i onclick='skip_"+divID+"(this);' class='Skip content_current' title='跳转'></i>";
	    }
	    operation+="</td>"
	}
     return operation;
}

function NewdealFooterPage(pageData,Initdata,parm,querydata){
	   //处理footer 分页
    var totalCount = pageData.totalCount;
    var pageSize = pageData.pageSize;
    var totalPage = pageData.totalPage;
    var pageNo = pageData.pageNo;
    var divID=parm.divID;
    
    if(totalCount===null || totalCount===''||totalCount===undefined ){
        //sysEcho("totalCount:"+totalCount);
        return;
    }
    if(pageSize===null || pageSize==='' ||pageSize===undefined){
        //sysEcho("pageSize:"+pageSize);
        return;
    }
    if(totalPage===null || totalPage==='' ||totalPage===undefined){
        //sysEcho("totalPage:"+totalPage);
        return;
    }
    if(pageNo===null || pageNo===''|| pageNo===undefined){
        //sysEcho("pageNo:"+pageNo);
        return;
    }
    
    

    
  
    var partsPageList=
        '<div class="table-actions" id="'+divID+'Select" style="float:left;"   >'+
        '展示条数:'+
        '<select id="'+divID+'pageSize"  style="width:60px;">'+
        '<option value="1" '+(pageSize==1?"selected":"")+'>1</option>'+
        '<option value="10" '+(pageSize==10?"selected":"")+'>10</option>'+
        '<option value="15" '+(pageSize==15?"selected":"")+'>15</option>'+
        '<option value="20" '+(pageSize==20?"selected":"")+'>20</option>'+
        '<option value="25" '+(pageSize==25?"selected":"")+'>25</option>'+
        '<option value="30" '+(pageSize==30?"selected":"")+'>30</option>'+
        '<option value="35" '+(pageSize==35?"selected":"")+'>35</option>'+
        '<option value="40" '+(pageSize==40?"selected":"")+'>40</option>'+
        '<option value="50" '+(pageSize==50?"selected":"")+'>50</option>'+
        '<option value="100" '+(pageSize==100?"selected":"")+'>100</option>'+
        '<option value="200" '+(pageSize==200?"selected":"")+'>200</option>'+
        '<option value="500" '+(pageSize==500?"selected":"")+'>500</option>'+
        '</select>'+
        '共'+totalCount+'条记录'+
        '</div>'+
        '<div class="pagination" style="float:right">'+
        '<ul>';
    
    //根据页数不同 写页脚
    
    //页首
    if(pageNo!==1 && pageNo!==0){
        partsPageList+='<li>'+(totalPage==1?"":'<a href="javascript:;"  onclick="jumpQuery(1,\''+divID+'\')">首页</a>')+'</li>';
        partsPageList+='<li>'+(totalPage==1?'':'<a href="javascript:;"  onclick="jumpQuery('+((pageNo-1)>1?(pageNo-1):1)+',\''+divID+'\')" >上一页</a>')+'</li>';
    }
    
    //页中
    if(pageNo<=2){ //少于两页
        for(var i=1;i<=(totalPage>5?5:totalPage);i++){
            partsPageList=partsPageList+'<li '+(pageNo==i?"class=active":"")+'><a href="javascript:;" onclick=jumpQuery('+i+',\''+divID+'\')>'+i+'</a>'+(pageNo==i?'<input type="hidden" id="currentPage" value="'+i+'"/>':"")+'</li>';
        }
    }else if((pageNo+2)>totalPage){  //总页数小于5页
        for(var i=(totalPage-4>0?totalPage-4:1);i<=totalPage;i++){
            partsPageList=partsPageList+'<li '+(pageNo==i?"class=active":"")+'><a href="javascript:;" onclick=jumpQuery('+i+',\''+divID+'\')>'+i+'</a>'+(pageNo==i?'<input type="hidden" id="currentPage" value="'+i+'"/>':"")+'</li>';
        }
    }else{
        for(var i=(pageNo>2?2:pageNo);i>=1;i--){
            partsPageList=partsPageList+'<li><a href="javascript:;" onclick="jumpQuery('+(pageNo-i)+',\''+divID+'\')">'+(pageNo-i)+'</a></li>';
        }
        partsPageList=partsPageList+'<li class="active"><a href="javascript:;" onclick="jumpQuery('+pageNo+',\''+divID+'\')">'+pageNo+'</a><input type="hidden" id="currentPage" value="'+pageNo+'"/></li>';
        for(var j=pageNo+1;j<=(totalPage<(pageNo+2)?totalPage:(pageNo+2));j++){
            partsPageList=partsPageList+'<li><a href="javascript:;" onclick="jumpQuery('+j+',\''+divID+'\')">'+j+'</a></li>';
        }
    }
    
    
    //尾页  和下一页
    if(totalPage!=pageNo){
        partsPageList+='<li>'+(totalPage==1?"":'<a href="javascript:;" onclick="jumpQuery('+((pageNo+1)<(totalPage)?(pageNo+1):(totalPage))+',\''+divID+'\')">下一页</a>')+'</li>';
        partsPageList+='<li>'+(totalPage==1?"":'<a href="javascript:;" onclick="jumpQuery('+(totalPage)+',\''+divID+'\')"  >尾页</a>')+'</li>';
    }
    partsPageList=partsPageList+  '</ul></div>';
    $(partsPageList).appendTo("#"+divID+"pageMenu");

    /**
     * 选择一页显示的页数跳转页面
     */
    $("#"+divID+"pageSize").change(function(){
    	jumpQuery(1,divID);
    });
}

/**
 * 跳转查询  下一页 等操作
 */
function jumpQuery(pageNO,divID){
	
	var divSelect=$("#"+divID+"pageMenu"); 
	var  Initdata=JSON.parse(divSelect.attr("initdata").replace(/'/g, '"'));
	var  parm=JSON.parse(divSelect.attr("parm").replace(/'/g, '"'));
	var  querydata=JSON.parse(divSelect.attr("querydata").replace(/'/g, '"'));
	var pageSize=$("#"+parm.divID+"pageSize option:selected").text();
	if(pageNO==''||pageNO==null){
		pageNO=1;
	}
	if(pageSize==''||pageSize==null){
		if(parm.isFooterPage){
			pageSize=10;
            }else{
            	pageSize=100;
            }
	}
	querydata.pageNo=pageNO;
	querydata.pageSize=pageSize;
	
	easyQuery(Initdata,parm,querydata);	
}
/**
 * 刷新查询
 */
function reQuery(divID){
	jumpQuery(1,divID);
}
function clean(divID){
	$("#"+divID+"pageTable").html("");//清空原数据
	$("#"+divID+"pageMenu").html("");//清空页脚
}

function newSelectAll(field){
	 var divID=$(field).attr("divID");
	// $("input[type='checkbox'][divID='"+divID+"']").attr("checked",field.checked);
	 $("input[type='checkbox'][divID='"+divID+"']").prop("checked",field.checked);
	 afterSelectAll(field);
}

/**
 * 关闭当前窗口
 */
function closeWindow(){
	var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

